$(function(){
    init_staff_distoer();
});
/**初始化部门列表*/
function init_staff_distoer(){
    $.post(ctx+"dept/getUseeAndDepttree",{},function (r) {
        var array  = r.msg;
        $("#using_json").jstree({
            "core": {"multiple": false,"data":array},
            "checkbox" : {"keep_selected_style" : false},
            "plugins" : [ "wholerow", "checkbox" ]
        });
        // 获得点击节点的id
        $('#using_json').on("changed.jstree", function (e, data) {
            var nodeid = data.node.id;
            var text = data.node.text;
            var label = "<div class='label label-danger p-3 m-3 pull-left' data-id='"+nodeid+"'>"+text+"</div>";
            $("#user-selectfor").empty().append(label);
        });
    });
}
/**点击分配客户的跟踪人员**/
function bigDisAginMyfenpei() {
    /**记录共享的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";
    var idss = ""; /**共享得id**/
    var types = ""; /**类型**/
    if (!ids.length) {$JuXue.n_warning("请勾选需要分配的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].uuid;
        idss += ids[i].id;types += ids[i].types;
        if (i !== (ids.length - 1)) {ids_arr += ",";idss += ",";types += ",";}
    }
    /**记录分配的人员**/
    var useridsArray = new Array();
    $("#user-selectfor").find("div").each(function () {
        var notselect = $(this).attr("data-id");
        useridsArray.push(notselect);
    });
    if (!useridsArray.length) {$JuXue.n_warning("请选择需要分配的用户信息！");return;}
    var bpDistribute = useridsArray.join(",");
    $.post(ctx+"myCustomer/companyMyCustomerDistore",{"uuid":ids_arr,ids:idss,"types":types,receiver:bpDistribute,},function (r) {
        if (r.code == 0){
            $JuXue.n_success("分配成功");
            $("#myCustomer-modal").modal("hide");
            var a = ".theme-panel", b = "active";
            $(a).removeClass(b);
            $("#selectTheme").hide();
            $JuXue.refreshTable('myEmpTable')
        }else{
            $JuXue.n_warning("分配失败");
        }
    });
}
